﻿using System;
using System.Diagnostics;
using System.Runtime.CompilerServices;

namespace HF
{
    class Program
    {
        static void Test1()
        {
            Console.WriteLine("==========单位毫秒==========");
            var str = Test.TestRead.ReadStructProperty();
            var cls = Test.TestRead.ReadClassProperty();
            OutPut("读属性", str, cls);

            str = Test.TestWrite.WriteStructProperty();
            cls = Test.TestWrite.WriteClassProperty();
            OutPut("写属性", str, cls);


            str = Test.TestRead.ReadStructField();
            cls = Test.TestRead.ReadClassField();
            OutPut("读字段", str, cls);

            str = Test.TestWrite.WriteStructField();
            cls = Test.TestWrite.WriteClassField();
            OutPut("写字段", str, cls);


            str = Test.TestRead.ReadStructIndexProperty();
            cls = Test.TestRead.ReadClassIndexProperty();
            OutPut("读索引", str, cls);

            str = Test.TestWrite.WriteStructIndexProperty();
            cls = Test.TestWrite.WriteClassIndexProperty();
            OutPut("写索引", str, cls);

            void OutPut(string name, long[] str, long[] cls)
            {
                Console.WriteLine($"{name}\t本地\t委托\t表达式\t反射");
                Console.WriteLine($"结构体\t{str[0]}\t{str[1]}\t{str[2]}\t{str[3]}");
                Console.WriteLine($"类对象\t{cls[0]}\t{cls[1]}\t{cls[2]}\t{cls[3]}");
                Console.WriteLine("===========================================================\r\n");
            }
        }

        static void Main(string[] args)
        {
            
            Test1();

            #region 其它测试

            //设置获取嵌套私有类私有属性
            var tst = Test.ClassObj.NewTst();
            var v = tst.SetValueExpr("Name", "张三")
                .GetValueExpr("Name");
            Console.WriteLine(v);

            //设置获取结构体属性
            object obj = new Test.StructObj() { Name = "张三" };
            var v1 = obj.SetValueExpr("Name", "李四")
                        .GetValueExpr(nameof(Test.StructObj.Name));
            Console.WriteLine(v1);
            Console.WriteLine(((Test.StructObj)obj).Name);

            #endregion
            Console.ReadLine();
        }
    }
}
